#include <iostream>
#include <vector>
using namespace std;
int main() {
    vector<string>all;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string str;
        cin >> str;
        all.push_back(str);
    }
    for (auto& str : all) {
        if (str.size() <= 2) {
            cout << str << endl;
            continue;
        }
        int i = 0, j = 1;
        while (j <= str.size()) {
            //aa
            if (str[j] == str[i]) {
                //aaa
                while (i > 0 && str[i - 1] == str[i]) {
                    str.erase(i, 1);
                    i--, j--;
                }
                //aa bb -> aa bb / aa bc
                while (i >= 2 && str[i - 2] == str[j - 2]&&str[i]==str[j]) {
                    str.erase(j, 1);
                }
            }
            i++, j++;
        }
        cout << str << endl;
    }
    return 0;
}